package agency.web.app.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MappedSuperclass;
import javax.persistence.Table;

@Entity
@Table(name = "users")
public abstract class AbstractUser implements User{
	
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "USER_ID")
	private int userId;
	
	@Column(name = "USER_TYPE")
	private String userType;
	
	@Column(name = "LOGIN")
	private String login;
	
	@Column(name = "PASSWORD")
	private String password;
	
	@Column(name = "NAME")
	private String name;
	
	@Column(name = "PHONE")
	private String phoneNumber;
	
	@Column(name = "EMAIL")
	private String email;
	
	@ManyToOne(targetEntity=Trip.class, fetch=FetchType.LAZY)
	@JoinColumn(name = "TRIP_ID")
	private Trip trip;
	
	
	public AbstractUser(){
	
	}
	public AbstractUser(String login,
			String password, String name, String phoneNumber, String email, Trip trip) {
		this.login = login;
		this.password = password;
		this.name = name;
		this.phoneNumber = phoneNumber;
		this.email = email;
		this.trip = trip;
	}
	
	public int getUserId() {
		return userId;
	}
	public void setUserId(int userId) {
		this.userId = userId;
	}
	
	public String getUserType() {
		if (this instanceof Agent){
		return "Agent";
		}
		if (this instanceof Client){
			return "Client";
		}
		return "UnknownType";
	}
	public void setUserType(String userType) {
		this.userType = userType;
	}
	public String getLogin() {
		return login;
	}
	public void setLogin(String login) {
		this.login = login;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public Trip getTrip() {
		return trip;
	}
	public void setTrip(Trip trip) {
		this.trip = trip;
	}
	

}
